home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / FIREEFF.ZIP / FIREEFF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-06  |  3.3 KB  |  91 lines

  1. {$G+}
  2. { Just a small example of the well known fire effect. }
  3.  
  4. uses crt;
  5.  
  6. var  ch    :    char;
  7.      fire  :    array[1..41,0..41] of byte;
  8.      i,j,k :    integer;
  9.  
  10. Procedure SetColor ( Color, Red, Green, Blue : Byte );
  11. Begin { SetColor }
  12.   Port[$3C8] := Color;
  13.   Port[$3C9] := Red;
  14.   Port[$3C9] := Green;
  15.   Port[$3C9] := Blue;
  16. end;  { SetColor }
  17.  
  18. begin
  19.   writeln(' UNICORN UTM 1994 presents:');
  20.   writeln(' A little fire effect by SHARP....');
  21.   delay(500);
  22.   asm
  23.     mov ax,13h
  24.     int 10h
  25.   end;
  26.   randomize;
  27.   { calculate your starting values...}
  28.   fillchar(fire,sizeof(fire),0);
  29.   for i:=0 to 41 do begin
  30.     { Hmm... well the maximum is 31.. does seem nice doesn't it:-)
  31.       I split this in a random and constant value, this will change
  32.       the effect in the way that you won't start with dark colors...
  33.       Try some values for yourself aslong as they add up to the maximum
  34.       colors you are using...}
  35.     fire[41,i]:=random(21)+10;
  36.   end;
  37.   for i:=1 to 10 do begin
  38.     { goin' from black to dark-gray to red to yellow, gives a nice effect..
  39.       I've only used 31 colors here because of my future use for this code,
  40.       You will probable be able to change this to 256... Then again if you
  41.       can't... STOP READING THIS AND STOP CODING!!! or get a good book that
  42.       expleans how to find the answer to 256 / 31 just to start with...}
  43.     setcolor(i,i*1,i*1,i*1);
  44.     setcolor(i+10,10+i*5,10,10);
  45.     setcolor(i+20,63,10+i*5,10);
  46.   end;
  47.   repeat
  48.     for i:=1 to 40 do begin
  49.       for j:=1 to 40 do begin
  50.        { O.K. the princeple is to calculate the average of a couple of points
  51.          below your now point and put it into the buffer... I doubled the
  52.          mid-point to add some extra effect, try some compinations for yourself...
  53.          You could also use some points on the line above or equal but you
  54.          will have to make a second buffer to copy the result in!!}
  55.         fire[i,j]:=(fire[i+1,j-1]+(fire[i+1,j] shl 1)+fire[i+1,j+1]) shr 2;
  56.       end;
  57.     end;
  58.     for i:=1 to 40 do begin
  59.       for j:=1 to 40 do begin
  60.         { ofcource for speed you could use the screen as your buffer so
  61.           you will be able to skip this.. but do remind yourself that
  62.           the screen memory is SLOW!! so it could also slow it down depending
  63.            on the size of your fire!! Again try which works best for you...}
  64.         mem[$a000:(80*320+120)+(i*320)+j]:=fire[i,j];
  65.       end;
  66.     end;
  67.     { add a new line... }
  68.     for i:=0 to 41 do begin
  69.       { Well if you've figured out how to use more colors don't forget
  70.         to change these values too!! You also probable noticed that
  71.         i've used diferent values that with the last random function...
  72.         This just changes the effect a little... Again this adds up to 31.
  73.         Just experiment with it....}
  74.       fire[41,i]:=random(26)+5;
  75.     end;
  76.   until keypressed;
  77.   ch:=readkey;
  78.   asm
  79.     mov ax,3h
  80.     int 10h
  81.   end;
  82. end.
  83.  
  84. { Simpel eh.... Amazing that a simple technice can produce an effect like
  85.   this, but that's mostly the case. Well this code is highly unoptimized but
  86.   I'll let you do that:-)... I wanne thank Phil Carlisle for telling me the
  87.   princeple of the fire effect... All credits for the initial idea go to
  88.   Jare (atleast as far as I know he did this first....)
  89.  
  90.   See Ya l8r, SHARP }
  91.